﻿using UnityEngine;
using System.Collections;

public class player : MonoBehaviour {

	public GameObject enemy;


	// Use this for initialization
	void Start () {
	
	}
	void OnDestroy()
	{
		Application.LoadLevel(Application.loadedLevelName);
	}
	
	// Update is called once per frame
	void Update () {

		if(Input.GetKeyDown(KeyCode.Mouse0))
		{
			Vector3 p=Camera.main.ScreenPointToRay (Input.mousePosition).GetPoint(Vector3.Distance(transform.position,Camera.main.transform.position)-0.5f*transform.localScale.x);
			Vector3 d = transform.position-p;
			float s = Camera.main.orthographicSize*10f;

			rigidbody2D.AddForce(d.normalized*s);

			if(transform.localScale.x>0.1f)
			{
				GameObject clone;
				clone=Instantiate(enemy,transform.position,transform.rotation)as GameObject;
				d*=-1f;
				clone.transform.localScale=transform.localScale*0.025f;

				clone.transform.Translate(d.normalized*(transform.localScale.x+clone.transform.localScale.x)/1.7f);
				clone.rigidbody2D.AddForce(d.normalized*transform.localScale.x*10f);

				float soso=(clone.transform.localScale.x/transform.localScale.x)/10;
				transform.localScale-=new Vector3(soso,soso,soso);
			}
		}
	
	}

	void OnGUI()
	{
		float vol = (transform.localScale.x*transform.localScale.x)*Mathf.PI;
		GUI.Label (new Rect(0,0,200,30),"Volume "+vol);
	}
}
